//House.h
//Created 12/05/14
//Created By Daniel Bowler
//
//This class represents the external model of a house. These will be used
//in our game to teleport over to a demo scene (which will demo some advanced
//rendering effects that we didnt bung in to the game / were too expensive
//to stick in the game)

#pragma once

//Inlclude Direct3D stuff
#include "d3dUtil.h"
//We inherit from this class. 
#include "AbstractModel.h"
#include "CollisionManager.h"

//The file path of the house model we are using
#define HOUSE_MODEL_FILE_PATH "Models/RuralStall.obj"
//Where we find the model's textures. 
#define HOUSE_MODEL_TEXTURE_FILE_PATH "Textures/House/Rural/"

//The house is used to transition to another scene (to demo some advanced
//rendering features)
//
//How many meters from the house do we need to be to transition. Pushing the E
//key will enter the scene
#define HOUSE_TRANSITION_RANGE 50.0f

//Forward declare our model - We will have multiple houses
//in the scene so we will use Hardware Instancing to render them
class StaticInstancedModel;

//And graphics interface - a pointer is passed when OnBatchAdd is called
class GraphicsInterface;

class House : public AbstractModel
{
public:
	//Standard constructor and destructor. 
	House();
	~House();

	//Inits the house model and loads our data
	void Init(ID3D11Device* device, unsigned numHousesInScene);

	//Creates an instance of the house - Pass in the orientation of the 
	//instance AND also the key to the scene which we transition to. 
	void CreateInstance(XMFLOAT3 position, XMFLOAT3 rotation, XMFLOAT3 scale,
		std::string sceneTransitionKey);

public:
	//Checks if any of the scenes houses are within HOUSE_TRANSITION_RANGE of the player. To decouple
	//the player and house, we instead pass the location of the player. 
	//
	//The two variables passed by reference first tell us what scene to transition too (string - pass
	//this to the SceneManager) and a bool to tell us if their is anything in range. 
	void IsHouseWithinRange(XMFLOAT3 locationOfPlayer, 
		std::string &sceneToTransitionOut, bool &isAHouseInRange);

	//Returns a pointer to the instanced model data
	StaticInstancedModel* GetModelData(){return houseExterior;};

public:
	//Called by the game scene to add this model to the GraphicsInterface batch.
	void AddToBatch(GraphicsInterface* gi);

private:
	//Represents our house model data - We load one from file. Note that
	//we are using Instanced models as we will have multiple instances of the same
	//house model but in differnt locations. 
	StaticInstancedModel* houseExterior; 

	//Vector of strings passed in when we create an instance. Represents the 
	//scenes we can transition too
	std::vector<std::string>scenesKey;

private:
	//Calculates the distance between two 3D vectors
	float GetDistance(XMFLOAT3 a, XMFLOAT3 b);

	// Hitbox used for collision detection
	std::vector<AABB> HitBox;

public:

	// Returns hitbox for collision detection
	AABB GetHitBox(unsigned instanceID);
};